
.pc =$0801 "Basic Upstart Program"
:BasicUpstart($0810)

//---------------------------------------------------------
//---------------------------------------------------------
//	Display a screen from a map of 3x3 multicolor chars 
//---------------------------------------------------------
//---------------------------------------------------------

.pc = $0810 "Main Program"
			ldx #0
!loop:
			.for(var i=0; i<4; i++) {
				lda #$00
				sta $0400+i*$100,x
				lda #$08
				sta $d800+i*$100,x
			}
			inx
			bne !loop-

			lda #11
			sta $d020
			sta $d021
			lda #3
			sta $d022
			lda #1
			sta $d023
			
			lda #$1e
			sta $d018
			lda $d016
			ora #16
			sta $d016
			lda #00
			sta $FA
			lda #04
			sta $FB
			lda #8
			sta ycount
			ldx #0
loopy:			lda #13
			sta xcount
loop:			lda map0,x
			jsr doTile
			clc
			lda $fa
			adc #3
			sta $fa
			bcc sk4
			inc $fb
sk4:			inx
			dec xcount
			bne loop
			clc
			lda $fa
			adc #81
			sta $fa
			bcc sk5
			inc $fb
sk5:			dec ycount 			
			bne loopy
			rts
ycount: .byte 8	
xcount: .byte 13	
doTile:			tay
			lda $fa
			pha
			lda $fb
			pha
			
			tya
			pha
			sta $fc
			lda #0
			sta $fd
			asl $fc
			rol $fd
			asl $fc
			rol $fd
			asl $fc
			rol $fd
			pla
			clc
			adc $fc
			sta $fc
			bcc sc
			inc $fd
			
sc:			clc
			lda #<tiles
			adc $fc
			sta $fc
			lda #>tiles
			adc $fd
			sta $fd
						
			ldy #0
			lda ($fc),y
			sta ($FA),y
			iny
			lda ($fc),y
			sta ($FA),y
			iny
			lda ($fc),y
			sta ($FA),y
			clc
			lda $fa
			adc #40-3
			sta $fa
			bcc sc2
			inc $fb
sc2:			iny
			
			lda ($fc),y
			sta ($FA),y
			iny
			lda ($fc),y
			sta ($FA),y
			iny
			lda ($fc),y
			sta ($FA),y
			clc
			lda $fa
			adc #40-3
			sta $fa
			bcc sc3
			inc $fb
sc3:			iny
			
			lda ($fc),y
			sta ($FA),y
			iny
			lda ($fc),y
			sta ($FA),y
			iny
			lda ($fc),y
			sta ($FA),y
			
			pla
			sta $fb
			pla
			sta $fa
			rts	

.var tilesbin = LoadBinary("tiles.raw")
tiles: .fill tilesbin.getSize(),tilesbin.get(i)

.var map0bin = LoadBinary("map.raw")
map0: .fill map0bin.getSize(),map0bin.get(i)
//---------------------------------------------------------
.pc = $3800
.var charset = LoadBinary("chars.raw")
.fill charset.getSize(), charset.get(i)